<!DOCTYPE html>
<html>
<link rel="shortcut icon" href="image/favicon.ico">

<head>
    <meta charset="UTF-8">
    <title>班级管理系统-登陆</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="./lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="./css/login.css">

    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="./js/jquery-3.5.1/jquery-3.5.1.js"></script>
    <script src="./lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <link rel="shortcut icon" href="./images/favicon.ico">

</head>

<body>
    <div  class="container3"  >
       

            <!-- 登录 -->
            <form class="layui-form" method="post" action="" name="loginform" id="loginform">
                <div class="login-box">
                    <h1>Admin Login</h1>
                    <input type="text" name="username" placeholder="用户名">
                    <input type="password" name="password" placeholder="密码">
                    <a class="layui-btn layui-btn-danger" lay-submit="" lay-filter="login">登录</a>
                </div>
            </form>
    
    
     
    </div>
   

    <script type="text/javascript" src="./js/jquery-3.5.1/jquery-3.5.1.js"></script>
    <script type="text/javascript" src="./common/url.js"></script>
    <!-- 注册点击事件 -->
    <!-- 登录部分 -->
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;

            // 登录过期的时候，跳出ifram框架
            if (top.location != self.location) top.location = self.location;

            // 进行登录操作

            form.on('submit(login)', function (data) {
                data = data.field;
                if (data.username == '') {
                    layer.msg('用户名不能为空');
                    return false;
                }
                if (data.password == '') {
                    layer.msg('密码不能为空');
                    return false;
                }

                $.ajax({
                    type: 'Post',

                    url: springURL+"/loginCheckForadmin",

                    dataType: 'json',
                    data: {
                        name: data.username,
                        password: data.password
                    },


                    success: function (loginCheck) {
                        console.log(loginCheck);
                        if (loginCheck.check == "登录成功") {
                            layer.msg('登录成功请稍后', { anim: 5 }, function () {
                                localStorage.setItem("username", data.username);
                                localStorage.setItem("userid", loginCheck.userid);


                                window.location = './indexAdmin.html';
                            });
                        }
                        if (loginCheck.check == "登录失败") {
                            layer.msg('登录失败', { anim: 5 }, function () {
                            })
                        }
                        return false;
                    },
                    error: function (jqXHR) {
                        console.log(jqXHR);
                        layer.msg('系统异常', function () {
                        })
                        return false;
                    }

                });
                return false;
            });

        });
    </script>
</body>

</html>